define(function(require, exports){
	var $ = require('jquery');
	var pubjs = require('pubjs');
	var highGrid  = require('@base/highGrid');
	var util = require('util');
	var utilDSP = require('modules/common');
	var CampaignType = pubjs.config("CONST/CAMPAIGN_TYPE");
	// 渲染名字
	function _renderName(i, val, data, con){
		var icon = [
			null,
			['running', LANG('已开启')],
			['pause', LANG('已暂停')],
			['store', LANG('已归档')]
		]
		var status = icon[data.Status] || {};
		if(data.IsDeleted){
			status = icon[3];
		}
		var name = '';
		if(data.IsGranted){
			name = $('<span/>');
		}else{
			name = $('<a/>');
		}

		// 名称点击跳转详情
		var editAction = '';
		editAction = '#serving/monitor' + utilDSP.getBrandSearch({'campaignId': data._id});

		name.attr({
			// 'target': '_blank',
			'href': editAction
		}).text(val).css({
			'vertical-align': 'middle'
		});

		var html = $([
			'<div class="text-truncate tl fl mr10" title="'+ val +'">',
				'<i title="'+status[1]+'" class="'+status[0]+' mr5"></i>',
			'</div>'
			].join('')).width(con.width-20).append(name);
		return html;
	}

	// 监控列表
	var MonitorList = highGrid.base.extend({
		init: function(config){
			config = pubjs.conf(0, config, {
					'url': 'campaign/list',
					'reqType': 'websocket',
					'cols': [
						{name: '_id', text: LANG('ID'), sort: false, width: 60, align: 'center'},
						{name:'Name', text:LANG('监控名称'), type:'index', width: 250, render:"renderName", align:'left'},
					],
					'hasSelect': true,
					'hasTab': true,
					'hasSwitch': false,
					'hasAmount': true,
					'hasSearch': true,
					'hasExport': true,
					'hasRefresh': true,
					'hasWordsSearch': false,
					'hasMenu': true,
					'isSendMetrics': true,
					'gridName': 'campaignMonitor',
					default_metrics: pubjs.config('metricsGroup/campaign/metrics'),
					tab: pubjs.config('metricsGroup/campaign/tabs'),
					param: {
						order: 'impressions|-1,clicks|-1',
						Type: CampaignType.AGENT
					},
					subFilter: 'subFilter',
					hasTrTitle: true,
					hasBatch: true,
					hasAutoRefresh: true,
				}
			);

			this.Super('init', arguments);
		},
		renderName: function(i, val, data, con){
			return _renderName(i, val, data, con);
		},


	});
	exports.monitorList = MonitorList;
});